package cn.bdqn.servlet;

import cn.bdqn.dao.HrInfoDao;
import cn.bdqn.dao.HrInfoDaoImpl;
import cn.bdqn.pojo.HrInfo;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author: 老鱼
 * @Date: 2019/1/5 16:41
 * @Description:
 */
@WebServlet(name = "DeleteServlet", urlPatterns = "/delete")
public class DeleteServlet extends HttpServlet {
    protected void doGet(HttpServletRequest request,
                         HttpServletResponse response)
            throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        //获取id
        Integer id=Integer.parseInt(request.getParameter("id"));
        //执行根据id删除数据的方法
        HrInfoDao dao=new HrInfoDaoImpl();
        int result=dao.del(id);
        //根据反馈的结果判断是否删除成功
        if(result>0){
            response.getWriter().print("<script>alert('删除成功');");
            //删除成功后，重新加载查询的方法，刷新数据
            response.getWriter().print("location.href='/index';</script>");
        }
    }
}
